function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function(){
    $(".news_review").submit(function (e) {
        e.preventDefault();
        // TODO 新闻审核提交
        var news_id = $("input[name='news_id']").val();
        var action = $("input:checked").val();
        var reason = $("textarea[name='reason']").val();
        var param = {
            "news_id": news_id,
            "action": action,
            "reason": reason
        };
        $.ajax({
            url: "/admin/news_review_detail",
            type: 'POST',
            contentType: 'application/json',
            dataType: 'json',
            data: JSON.stringify(param),
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            success: function (resp) {
                if(resp.errno == '0'){
                    // 成功，界面刷新
                    // 返回上一页，刷新数据
                    location.href = document.referrer;
                }else{
                    alert(resp.errmsg)
                }
            }
        })

    })
});

// 点击取消，返回上一页
function cancel() {
    history.go(-1)
}